__author__ = 'wangd'
# coding: utf-8
# Time : 2017/2/19 19:56
import urllib.request,json
import re
import urllib.parse

zhPattern = re.compile(u'[\u4e00-\u9fa5]+')
def urldata(url):#返回请求URL的json
    c=urllib.request.urlopen(url)
    url_dic=json.loads(c.read().decode('utf-8'))
    return url_dic

def hz_encode(url):#用urlcode替换字符串中的汉字
    while zhPattern.search(url):
        match = zhPattern.search(url)
        hz=match.group(0)
        v=urllib.parse.quote(hz)
        new_url=url.replace(hz,v)
        url=new_url
    return url